package com.dream.wukong.common.core.importexport.csv.converters;

import com.dream.wukong.common.core.importexport.csv.Converter;
import com.dream.wukong.common.core.importexport.csv.annotation.CsvConverter;
import com.dream.wukong.common.core.util.FileUtil;
import org.apache.commons.validator.GenericValidator;
import org.springframework.stereotype.Component;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 16:01 2018/9/17.
 * @Modified:
 */
@Component("fileSizeConverter")
@CsvConverter
public class FileSizeConverter implements Converter {
    @Override
    public String convert(Object value) {
        if(value!=null && GenericValidator.isLong(value.toString()))
            return FileUtil.byteCountToDisplaySize(Long.valueOf(value.toString()));
        else {
            return  "";
        }
    }
}
